<?
$baseDir = dirname(dirname(__FILE__));
require_once "$baseDir/install/install.inc.php";
require_once "$baseDir/lib/adodb/adodb.inc.php";

$AppUI =& new InstallerUI; // Fake AppUI class to appease the db_connect utilities.

$dbtype = trim( dPInstallGetParam( $_POST, 'dbtype', 'mysql' ) );
$dbhost = trim( dPInstallGetParam( $_POST, 'dbhost', '' ) );
$dbname = trim( dPInstallGetParam( $_POST, 'dbname', '' ) );
$dbuser = trim( dPInstallGetParam( $_POST, 'dbuser', '' ) );
$dbpass = trim( dPInstallGetParam( $_POST, 'dbpass', '' ) );

$db = NewADOConnection($dbtype);

if(!empty($db)) {
	$dbc = $db->Connect($dbhost,$dbuser,$dbpass);
	if ($dbc) $existing_db = $db->SelectDB($dbname);
} else {
	$dbc = false;
}

if( $dbc ) {
	require_once( "$baseDir/lib/adodb/adodb-xmlschema.inc.php" );

	$schema = new adoSchema( $db );

	$sql = $schema->ExtractSchema(true);

	header('Content-Disposition: attachment; filename="sdp.dbBackup.'.date("Ymd").date("His").'.xml"');
	header('Content-Type: text/xml');
	echo $sql;
	exit();
}

?>
<html>
<head>
	<link rel="stylesheet" type="text/css" href="../style/default/main.css">
</head>
<body>
<center>
<br/>
<br/>
<br/>
<table class="infopanel" border="0" cellpadding="0" cellspacing="0">
<tr style="font-weight: bold">
<td style="padding: 48px; background: #FFF; font-size: 150%" align="center">
<span class="error">ERROR: No Database Connection available! - Backup not performed!</span>
</td>
</tr>
</table>
</center>
</body>
</html>
